package MainTest;

import java.util.ArrayList;
import java.util.Stack;

/**
 * Created by xuyi on 2017/2/11.
 */
public class LinkedListNode {


    public class ListNode {
        int val;
        ListNode next = null;

        ListNode(int val) {
            this.val = val;
        }
    }

    class Solution {

        public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
            Stack<Integer> stack = new Stack<>();

            while (listNode != null) {
                stack.add(listNode.val);
                listNode = listNode.next;
            }
            ArrayList<Integer> rst = new ArrayList<>();
            while (!stack.isEmpty()) {
                rst.add(stack.pop());
            }
            return rst;
        }
    }




}
